package net.vinote.sosa.context.support;

import java.io.IOException;

import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.core.io.Resource;

public class SosaGenericXmlApplicationContext extends GenericXmlApplicationContext {
	private SosaResource sosaResource = new SosaResource(this);

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.context.support.GenericApplicationContext#getResource
	 * (java.lang.String)
	 */
	@Override
	public Resource getResource(String location) {
		return sosaResource.getProxyResource(super.getResource(location));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.context.support.GenericApplicationContext#getResources
	 * (java.lang.String)
	 */
	@Override
	public Resource[] getResources(String locationPattern) throws IOException {
		try {
			if (!sosaResource.isInit()) {
				sosaResource.init(super.getResource("classpath:sosa-conf.properties"));
			}
			return sosaResource.getResources(locationPattern, super.getResources(locationPattern));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.getResources(locationPattern);
	}

}
